/*
 * @(#)EmailMessageSenderComparator.java
 *
 * Copyright (c) 2004 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */

package com.dcivision.upgrade;

/**
 * General behaviors to handles exception caused in upgrade.
 * 
 * @author      Brook.Huang
 * @company     DCIVision Limited
 * @creation    19/04/2007
 * @version     $Revision: 1.4 $
 */
public class GeneralExceptionHandler extends UpgradeExceptionHandler {

  public GeneralExceptionHandler() {
    super();
  }

  public GeneralExceptionHandler(String exceptionClassName) {
    super(exceptionClassName);
  }

  /**
   * If any exception causes, rollback DB.
   */
  public void handleException(UpgradeContext upgradeContext) throws Exception {
    upgradeContext.logReport("<p><font color=red>Upgrading operation is faild, try to rollback DB.</font></p>\n", null);

    try {
      upgradeContext.getUpgradeConnection().rollback();
      upgradeContext.setUpgradeCompleted(true);
      upgradeContext.logReport("<p><font color=red>DB rollback sucess!</font></p>\n", null);
    } catch (Exception e) {
      log.fatal("DB rollback faild!", e);
      throw e;
    } finally {
      try {
        upgradeContext.getUpgradeConnection().close();
      } catch (Exception e) {
        // Ignore exception.
      }
    }
  }

}
